package com.whu.waterworks.action;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

import com.opensymphony.xwork2.ActionSupport;
import com.whu.waterworks.model.WaterUser;
import com.whu.waterworks.service.StationnumpositionService;
import com.whu.waterworks.service.WaterUserService;
import com.whu.waterworks.service.WaterWorksUserService;

/**
 * 
 * @author cai
 * @date   2016-3-10
 */
public class UserInfoAction extends ActionSupport{
	private static final long serialVersionUID = 8959653101044024540L;
	WaterUser waterUser;	//当前登录的用户信息
	WaterWorksUserService waterWorksUserService;
	@Override
	public String execute() throws Exception {
		Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
		if (authentication.getPrincipal() instanceof UserDetails) {
		UserDetails userDetails=(UserDetails)authentication.getPrincipal();
		waterUser=waterWorksUserService.getUserByName(userDetails.getUsername());
		System.out.println(""+waterWorksUserService.getUserByName(userDetails.getUsername()).getUsername());
		}
		return SUCCESS;
	}
	
	public WaterUser getWaterUser() {
		return waterUser;
	}
	public void setWaterUser(WaterUser waterUser) {
		this.waterUser = waterUser;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public WaterWorksUserService getWaterWorksUserService() {
		return waterWorksUserService;
	}

	public void setWaterWorksUserService(WaterWorksUserService waterWorksUserService) {
		this.waterWorksUserService = waterWorksUserService;
	}

	
}
